package com.example.food_diary;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FoodAdapter extends ArrayAdapter<Food_List>{
	private ArrayList<Food_List> food;
	
	public FoodAdapter(Context context, int resource, ArrayList<Food_List> food) {
		super(context, resource, food);
		this.food = food;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		
		if(v == null) {
			LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.simple_list, null);
		}
		
		Food_List p = food.get(position);
		
		if(p != null) {
			ImageView sfood_img = (ImageView) v.findViewById(R.id.simple_food_img);
			TextView sfood_name = (TextView) v.findViewById(R.id.simple_food_name);
			TextView sfood_date = (TextView) v.findViewById(R.id.simple_date);
			
			sfood_img.setImageResource(p.getFood_img());
			sfood_name.setText(p.getFood_name());
			sfood_date.setText(p.getFood_date());
		}
			
		return v;
	}
	
}
